package com.lingjtx.im.core.distribute;

import com.lingjtx.common.core.constant.MqConst;
import com.lingjtx.common.thread.mq.RabbitSenderTemplate;
import com.lingjtx.im.core.protocol.ProtocolWrapper;
import org.springframework.stereotype.Service;

/**
 * 发送消息（RabbitMQ 发布）
 */
@Service
public class MessagePublisher {

    private final RabbitSenderTemplate rabbitSenderTemplate;

    public MessagePublisher(RabbitSenderTemplate rabbitSenderTemplate) {
        this.rabbitSenderTemplate = rabbitSenderTemplate;
    }

    public void publish(ProtocolWrapper wrapper) {
        // 发主业务队列，所有消息都入库、推送
        rabbitSenderTemplate.convertAndSend(MqConst.IM_EXCHANGE_NAME,
                MqConst.IM_ROUTING_MAIN_KEY,
                wrapper);
    }

    public <T> void publish(String routingKey, T message) {
        rabbitSenderTemplate.convertAndSend(MqConst.IM_EXCHANGE_NAME, routingKey, message);
    }
}
